<template>
  <view class="">
    <u-form-item :label="item.label" :prop="item.value" :borderBottom="item.iscard != 'after' && item.iscard != 'card'"
      :labelPosition="(item.attrs && item.attrs.labelPosition) || 'left'" ref="item1">
      <!-- :required="true" -->
      <u--textarea v-if="item.type == 'textarea'" placeholder="请输入内容" v-model="inputValue" border="none"
        @blur="blur"></u--textarea>
      <u--input v-else placeholder="请输入内容" v-model="inputValue" border="none" @blur="blur"></u--input>
    </u-form-item>
  </view>
</template>

<script>
export default {
  props: {
    item: {
      typeof: Object,
      default: () => {
        return {};
      },
    },
    data: {
      typeof: Object,
      default: () => {
        return {};
      },
    },
    value: {
      typeof: [String, Number, Boolean, Array, Object],
      default: () => {
        return "";
      },
    },
  },
  data() {
    return {
      inputValue: "",
    };
  },
  watch: {
    value: {
      handler(n, o) {
        let value = this.value;
        let item = this.item;
        if (!item.value) {
          value = item.defaultValue || ''
        }

        if (item.fl && value && Number(value).div(Number(item.fl)) != 0) {
          value = Number(value).div(Number(item.fl))
        }
        // state.inputValue = value
        this.inputValue = value;
      },
      immediate: true,
      deep: true
    },
  },
  methods: {
    blur() {
      let item = this.item;
      let value = this.inputValue;
      if (item.fl && value && Number(value).div(Number(item.fl)) != 0) {
        value = String(parseInt(Number(value).mul(Number(item.fl))))
      }
      this.$emit("input", value);
    },
  },
};
</script>

<style></style>